#include <bits/stdc++.h>

const int maxn=550;
const int maxl=10000010;

int ch[maxn][26],fail[maxn],lst[maxn],q[maxn],val[maxn];
int cnt[10];
char str[maxl],s[15][55];
int nodes;

int main(){
    int n,f,r;

    freopen("ACautomata.in","r",stdin);
    freopen("ACautomata.out","w",stdout);

    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",s[i]);
        int len=strlen(s[i]);
        int cur=0;
        for(int j=0;j<len;j++){
            if(!ch[cur][s[i][j]-'a']) ch[cur][s[i][j]-'a']=++nodes;
            cur=ch[cur][s[i][j]-'a'];
        }
        val[cur]=i;
    }

    f=r=0;
    for(int i=0;i<26;i++) if(ch[0][i]) q[r++]=ch[0][i];
    for(;f<r;f++){
        const int &cur=q[f];
        for(int j=0;j<26;j++){
            if(!ch[cur][j]) continue;
            int t=fail[cur];
            while(t&&!ch[t][j]) t=fail[t];
            if(ch[t][j]) t=ch[t][j];
            fail[ch[cur][j]]=t;
            lst[ch[cur][j]]=val[fail[ch[cur][j]]]?fail[ch[cur][j]]:lst[fail[ch[cur][j]]];
            q[r++]=ch[cur][j];
        }
    }

    scanf("%s",str);
    int cur=0;
    int len=strlen(str);
    for(int i=0;i<len;i++){
        while(cur&&!ch[cur][str[i]-'a']) cur=fail[cur];
        if(ch[cur][str[i]-'a']){
            cur=ch[cur][str[i]-'a'];
            int t=cur;
            if(!val[t]) t=lst[t];
            while(t){
                cnt[val[t]]++;
                t=lst[t];
            }
        }
    }

    for(int i=1;i<=n;i++) printf("%s %d\n",s[i],cnt[i]);
    return 0;
}
